package com.mt.api.modules.controller;


import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import com.mt.log.annotation.Log;
import com.mt.api.modules.domain.bo.StockTakingAddBo;
import com.mt.api.modules.domain.bo.StockTakingCancelBo;
import com.mt.api.modules.domain.bo.StockTakingPageBo;
import com.mt.api.modules.domain.vo.StockTakingAndDetailVo;
import com.mt.api.modules.service.IStockTakingService;
import com.mt.api.util.ParamsValid;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: plover
 * @Date: 2022-04-30
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/app/stock/taking")
public class StockTakingController {

    @Autowired
    private IStockTakingService stockTakingService;

    @PostMapping("/add")
    @Log("库存盘点单增加")
    @ApiOperation(value = "", notes = "库存盘点单增加", httpMethod = "POST")
    public WebResponse addStockTaking(@RequestBody StockTakingAddBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("盘点明细不能为空", bo);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return stockTakingService.addStockTaking(bo);
    }

    @GetMapping("/page")
    @Log("库存盘点单分页列表")
    @ApiOperation(value = "", notes = "库存盘点单增加", httpMethod = "GET")
    public WebResponse getStockTakingPage(StockTakingPageBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("pageNum不能为空", bo.getPageNum())
                .validNotNull("pageSize不能为空", bo.getPageSize());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return stockTakingService.getStockTakingPage(bo);
    }

    @GetMapping("/detail")
    @Log("库存盘点单明细")
    @ApiOperation(value = "", notes = "库存盘点单增加", httpMethod = "GET")
    public WebResponse<StockTakingAndDetailVo> getStockTakingDetail(Integer id) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("id不能为空", id);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return stockTakingService.getStockTakingDetail(id);
    }

    @PostMapping("/cancel")
    @ApiOperation(value = "", notes = "库存盘点单撤销", httpMethod = "POST")
    public WebResponse cancelStockTaking(@RequestBody StockTakingCancelBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("id不能为空", bo.getStockTakingId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return stockTakingService.cancelStockTaking(bo);
    }

}